layui.config({
    base: '../../../eui/plugins/layui-extend/' //这是你存放拓展模块的根目录
});

layui.use(['form'], function () {
    var form = layui.form;
    var id = getParam("id");
	dictToRadios("type","strategyNodeType","type","1");
    io.get("/strategy/strategies?queryChildren=false&pageNo=1&pageSize=-1", function(res) {
		console.log(res)
		var data = res.data.list;
		var map = new Map();
		for (var i in data) {
			var d = data[i];
			map.set(d.id.toString(), d.strategyName);
		}
		map2Select(map,'parentId');
		if(!isNull(id)){
	    	io.get('/strategy/strategies/' + id,function(res){
	    		var data = res.data;
	            var form = layui.form;
	            //表单初始赋值
	            form.val('lForm', data)
	            form.render();
	    	});
    	}
	});

    //监听提交
    form.on('submit(save)', function (form) {
        var data=form.field;
		io.post('/strategy/strategies',JSON.stringify(data),function(res){
	               setTimeout(function(){return closePage();},1000);
	               window.parent.refreshTableData();
		});
		return false;
    });
});

function dictToRadios(elementId,parentCode,itemName,checkedItem){
	var kvMap=dictionary(parentCode);
	var innerHtml="";
	kvMap.forEach(function(v,k,map){
		 var checked="";
			if(checkedItem!=null&&checkedItem==k){
				checked="checked";
            }
			innerHtml = innerHtml + '<input type="radio" name="'+itemName+'" lay-filter="'+itemName+'" title="'+v+'" value="'+k+'" '+checked+'>';
	});
	$("#"+elementId).html(innerHtml);
}